﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using CthulhuDomain;
using CthulhuDomain.GameEntities;
using CthulhuDomain.StageManagement;
using Microsoft.Pex.Framework;
using Microsoft.Pex.Framework.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Invaders.Test.Factories.GameEntities
{
  [TestClass]
  public partial class MenuCommandFactoryFixture
  {
    private static ContentManager contentManager;
    private SpriteBatchAdapter spriteBatch;
    private GameServiceManager gameServiceManager;

    [TestInitialize]
    public void TestInitialize() {
      var gd = new MockedGraphicsDeviceService(DeviceType.Hardware, GraphicsProfile.HiDef);
      gd.CreateDevice();

      string activeConfinguration;
#if DEBUG
      activeConfinguration = "Debug";
#else
      activeConfinguration = "Release";

#endif
      spriteBatch = new SpriteBatchAdapter(gd.GraphicsDevice);
      contentManager = new ContentManager(gd.ServiceProvider) {
        RootDirectory = Path.GetFullPath(string.Format("../../../CthulhuInvaders/bin/x86/{0}/Content/", activeConfinguration))
      };

      gameServiceManager = new GameServiceManager(new GameAdapter(new Game()), new ContentManagerAdapter(contentManager), spriteBatch, new RectangleAdapter(0, 0, 300, 300));
    }

    [TestCleanup]
    public void MyTestCleanup() {
      contentManager = null;
      spriteBatch = null;
      gameServiceManager = null;
    }

    [PexMethod, PexAllowedException(typeof(InvalidEnumArgumentException))]
    public MenuCommandFactory MenuCommandFactory_GetFactory_ShouldBeNotNull(MenuCommandFactory.eTypeFactory typeFactory) {
      // Arrange
      // Act
      var factory = MenuCommandFactory.GetFactory(typeFactory);
      // Assert
      Assert.IsNotNull(factory);
      Trace.WriteLine(string.Format("Type of instanced command factory is : {0};", factory.GetType()));

      return factory;
    }

    [PexMethod, PexAllowedException(typeof(InvalidEnumArgumentException))]
    public MenuCommand MenuCommandFactory_CreateCommand_ShouldBeNotNull(MenuCommandFactory.eTypeFactory typeFactory) {
      // Arrange
      var factory = MenuCommandFactory_GetFactory_ShouldBeNotNull(typeFactory);
      // Act
      var command = factory.CreateCommand(gameServiceManager);
      // Assert
      Assert.IsNotNull(command);
      Trace.WriteLine(string.Format("Type of instanced command is : {0};", command.GetType()));

      return command;
    }

  }
}
